package com.hsjk.szwj.module.train.controller.admin;

import com.hsjk.szwj.framework.common.pojo.CommonResult;
import com.hsjk.szwj.framework.common.pojo.PageResult;
import com.hsjk.szwj.module.train.controller.admin.vo.AdminCourseVideoCreateReqVO;
import com.hsjk.szwj.module.train.controller.admin.vo.AdminCourseVideoDetailRespVO;
import com.hsjk.szwj.module.train.controller.admin.vo.AdminCourseVideoPageReqVO;
import com.hsjk.szwj.module.train.controller.admin.vo.AdminCourseVideoPageRespVO;
import com.hsjk.szwj.module.train.controller.admin.vo.AdminCourseVideoPageSearchReqVO;
import com.hsjk.szwj.module.train.controller.admin.vo.AdminCourseVideoPageSearchRespVO;
import com.hsjk.szwj.module.train.controller.admin.vo.AdminCourseVideoUpdateReqVO;
import com.hsjk.szwj.module.train.service.ICourseVideoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

import static com.hsjk.szwj.framework.common.pojo.CommonResult.success;

/**
 * @author chenjiawei
 * @desc
 * @Date 2023/10/28 18:25
 **/
@Tag(name = "后台管理端 - 课程视频相关接口")
@RestController
@RequestMapping("/train/course/video")
@Validated
public class AdminCourseVideoController {

    @Resource
    private ICourseVideoService courseVideoService;

    @PostMapping("/page-course-video")
    @Operation(summary = "分页获取课程视频列表")
    @PreAuthorize("@ss.hasPermission('train:course-video:query')")
    public CommonResult<PageResult<AdminCourseVideoPageRespVO>> getCourseVideoPage(
            @RequestBody @Valid AdminCourseVideoPageReqVO reqVO) {
        return success(courseVideoService.getCourseVideoPage(reqVO));
    }

    @PostMapping("/page-course-video-search")
    @Operation(summary = "课程视频分页查询")
    @PreAuthorize("@ss.hasPermission('train:course-video:query')")
    public CommonResult<PageResult<AdminCourseVideoPageSearchRespVO>> getCourseVideoSearchPage(
            @RequestBody @Valid AdminCourseVideoPageSearchReqVO reqVO) {
        return success(courseVideoService.getCourseVideoSearchPage(reqVO));
    }

    @GetMapping("/get-course-video-detail")
    @Operation(summary = "获取课程视频详情")
    @PreAuthorize("@ss.hasPermission('train:course-video:query')")
    public CommonResult<AdminCourseVideoDetailRespVO> getCourseVideoDetail(@RequestParam Long id) {
        return success(courseVideoService.getCourseVideoDetail(id));
    }

    @PostMapping("/create")
    @Operation(summary = "创建课程视频")
    @PreAuthorize("@ss.hasPermission('train:course-video:create')")
    public CommonResult<Boolean> createCourseVideo(@RequestBody @Valid AdminCourseVideoCreateReqVO reqVO) {
        return success(courseVideoService.createCourseVideo(reqVO));
    }

    @PostMapping("/update")
    @Operation(summary = "更新课程视频")
    @PreAuthorize("@ss.hasPermission('train:course-video:update')")
    public CommonResult<Boolean> updateCourseVideo(@RequestBody @Valid AdminCourseVideoUpdateReqVO reqVO) {
        return success(courseVideoService.updateCourseVideo(reqVO));
    }

    @PostMapping("/delete")
    @Operation(summary = "删除课程视频")
    @PreAuthorize("@ss.hasPermission('train:course-video:delete')")
    public CommonResult<Boolean> deleteCourseVideo(@RequestParam Long id) {
        return success(courseVideoService.deleteCourseVideo(id));
    }
}
